package cn.edu.dgut.css.sai.restfulsvc.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 企业级软件开发-实训课程：Spring Boot 2.2.2
 *
 * @author 黎志雄
 * 2019-12-12
 */
@SuppressWarnings("JpaDataSourceORMInspection")
@Table(name="ACCOUNT")
@Entity
@Data
public class Account implements Serializable {

	@Id
	@GeneratedValue
	@Column(name="ACCOUNTNUMBER",updatable = false)
	private Integer accountNumber;

	@Column(name="ACCOUNTNAME")
	private String accountName;

	@Column(name="BALANCE")
	private BigDecimal balance;

	@Column(name="OPENINGDATE")
	private LocalDate openingDate;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "CUSTOMERID", nullable = false)
    @OnDelete(action = OnDeleteAction.CASCADE) // 删除customer时，联级删除所有account，这是数据库处理的，与ORM无关。cascade=CascadeType.REMOVE级联将由orm（hibernate）处理。
    @JsonIgnore
    private Customer customer;

}
